<?php
declare(strict_types=1);

namespace Modules\Systemsetting\Http\Controllers;

use Catch\Base\CatchController as Controller;
use Modules\Systemsetting\Models\Systemsetting;
use Illuminate\Http\Request;
use extend\services\warehouse\{warehouseService};//引入自定义类


class SystemsettingController extends Controller
{
    public function __construct(
        protected readonly Systemsetting $model
    ){}

    /**
     * @param Request $request
     * @return mixed
     */
    public function index(): mixed
    {
      
        $kingDeeService = new warehouseService();
        $datauser = $kingDeeService->uerdata();
        $data = $this->model->getList();
        foreach($data as $k=>$v){
            $data[$k]['modifier'] = isset($datauser[$v['modifier']])?$datauser[$v['modifier']]:'';
            $data[$k]['creator_id'] = isset($datauser[$v['creator_id']])?$datauser[$v['creator_id']]:'';
        }
        return $data;
    }

    /**
     * @param Request $request
     * @return mixed
     */
    public function store(Request $request)
    {
        return $this->model->storeBy($request->all());
    }

    /**
     * @param $id
     * @return mixed
     */
    public function show($id)
    {
        return $this->model->firstBy($id);
    }

    /**
     * @param Request $request
     * @param $id
     * @return mixed
     */
    public function update($id, Request $request)
    {   $data = $request->all();
     
        $data['modifier'] =$this->getLoginUserId();//当前登录用户名称
        return $this->model->updateBy($id, $data);
    }

    /**
     * @param $id
     * @return mixed
     */
    public function destroy($id)
    {
        return $this->model->deleteBy($id);
    }
}
